﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;

using DbSharp.Framework.Assertion;
using DbSharp.Framework.CaseFile;
using DbSharp.Framework.TestEngine;

namespace DbSharp.GuiRunner.ViewItems
{
    [Obfuscation]
    class UnitCaseViewItem : INotifyPropertyChanged
    {
        #region Private members

        private UnitTestRunner m_CaseRunner;
        private ImageList m_ListStateImage;
        private ImageList m_ListExportedImage;
        private string m_CaseName;
        private CaseTestState m_State;
        private Image m_StateImage;
        private bool m_ExportedState;
        private Image m_ExportedImage;
        private AssertionType m_AssertionType;
        private string m_AssertionText;

        #endregion

        public UnitCaseViewItem(ImageList listStateImage, ImageList listExportedImage, UnitTestRunner caseRunner)
        {
            m_ListStateImage = listStateImage;
            m_ListExportedImage = listExportedImage;
            m_CaseRunner = caseRunner;
            Refresh();
        }

        #region Public property/method

        public UnitTestRunner TestRunner
        {
            get { return m_CaseRunner; }
        }


        public void Refresh()
        {
            this.CaseName = m_CaseRunner.TestCase.TestCaseName;
            this.State = m_CaseRunner.CaseExecuteResult.TestState;
            this.AssertionType = m_CaseRunner.TestCase.Assertion;
            this.ExportedState = m_CaseRunner.CaseExecuteResult.ExportedFlag;
        }


        public string CaseName
        {
            get { return m_CaseName; }
            private set
            {
                m_CaseName = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("CaseName"));
                }
            }
        }

        public CaseTestState State
        {
            get { return m_State; }
            set
            {
                m_State = value;
                m_StateImage = m_ListStateImage.Images[(int)m_State];
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("StateImage"));
                }
            }
        }

        public Image StateImage
        {
            get { return m_StateImage; }
        }

        public bool ExportedState
        {
            get { return m_ExportedState; }
            private set
            {
                m_ExportedState = value;
                if (m_ExportedState == false)
                    m_ExportedImage = m_ListExportedImage.Images[0];
                else
                    m_ExportedImage = m_ListExportedImage.Images[1];
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("ExportedImage"));
                }
            }
        }


        public Image ExportedImage
        {
            get { return m_ExportedImage; }
        }


        public AssertionType AssertionType
        {
            get { return m_AssertionType; }
            private set
            {
                m_AssertionType = value;
                m_AssertionText = m_AssertionType.ToString();
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("AssertionText"));
                }
            }
        }

        public string AssertionText
        {
            get { return m_AssertionText; }
        }

        string m_ProgressText = string.Empty;
        public string ProgressText
        {
            get { return m_ProgressText; }
            set
            {
                m_ProgressText = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("ProgressText"));
                }
            }
        }
        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }


}
